package response

import (
	"gintify/core"
	"github.com/gin-gonic/gin"
	"net/http"
)

//{
//	"code": 2001,
//	"msg": xxx,
//	"data": xxx
//}

type Resp struct {
	Msg  string      `json:"msg"`
	Body interface{} `json:"body"`
	Code int         `json:"code"`
}

func Response(c *gin.Context, httpStatus int, code int, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	c.JSON(httpStatus, gin.H{"code": code, "msg": msg, "body": data})
}

func Success(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusOK, http.StatusOK, msg, data)
}

func Created(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusCreated, http.StatusCreated, msg, data)
}
func Updated(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusAccepted, http.StatusAccepted, msg, data)
}
func Deleted(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusOK, http.StatusOK, msg, data)
}
func Fail(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusBadRequest, http.StatusBadRequest, msg, nil)
}

func Error(c *gin.Context, msg string, data interface{}) {
	core.LG.Debugf("%s %v\n", msg, data)
	Response(c, http.StatusInternalServerError, http.StatusInternalServerError, msg, nil)
}
